package com.dewod.producesales.model.view;


import com.blankj.utilcode.util.ObjectUtils;

public class RequestSetting {

    public static final String KEY_REQUEST = "requestSetting";

    private String schema;

    private String ip;

    private String port;

    private String prefix;


    private RequestSetting(String schema, String ip, String port, String prefix) {
        this.schema = schema;
        this.ip = ip;
        this.port = port;
        this.prefix = prefix;
    }

    public RequestSetting() {}
    public static RequestSetting init() {
//        return new RequestSetting("http","176.16.20.226","7788","pda/app");

         return new RequestSetting("https","dwfk.dewod.com","8190","api/pda/app");
    }

    public String getSchema() {
        return schema;
    }

    public void setSchema(String schema) {
        this.schema = schema;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getUrl(){
        if (ip == null || port == null || schema == null) {
            throw new IllegalArgumentException("ip, port, and schema cannot be null");
        }

        StringBuilder result = new StringBuilder();
        result.append(schema).append("://").append(ip);

        // 判断是否需要添加端口号
        if (!(ObjectUtils.equals("https", schema) && ObjectUtils.equals("443", port)) &&
                !(ObjectUtils.equals("http", schema) && ObjectUtils.equals("80", port))) {
            result.append(":").append(port);
        }
        // 拼接前缀
        if(ObjectUtils.isNotEmpty(prefix)){
            result.append("/").append(prefix);
        }

        return result.toString();
    }
}
